package com.syg.task;

import org.springframework.cloud.gateway.event.RefreshRoutesEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.lang.NonNullApi;
import org.springframework.stereotype.Component;

import java.util.TimerTask;

@Component
public class RefreshRouteConfigTask extends TimerTask implements ApplicationEventPublisherAware {

    private ApplicationEventPublisher publisher;


    @Override
    public void run() {
        refreshRouteConfig();
    }

    /**
     * 定时刷新路由配置缓存
     * @author syg
     */
    public void refreshRouteConfig() {
        System.out.println(("路由配置已刷新！！！"));
        this.publisher.publishEvent(new RefreshRoutesEvent(this));
    }

    @Override
    public void setApplicationEventPublisher( ApplicationEventPublisher applicationEventPublisher) {
        this.publisher = applicationEventPublisher;
    }
}
